
import getApiData, { getNestApiData } from "@/services/cpasRequest";

// 

export async function getPersonnelList(params: {
    dbname: string;
}) {
    if (!params.dbname) return Promise.resolve({
        data: [],
        success: false,
    });;
    const res = await getApiData('accountingEntryTest.account.getPersonnelList', params);
    if (res.ok) {
        return Promise.resolve({
            data: res.data,
            success: true,
        });
    }
    return Promise.resolve({
        data: [],
        success: false,
    });
}
export async function updateSaveDataBatch(params: {
    dbname: string;
    guid: string;
    code: string;
    name: string;
    job: string;
}[]) {
    const res = await getApiData('accountingEntryTest.accountant.saveBatchData', params);
    if (res.ok) {
        return Promise.resolve({
            data: res.data,
            success: true,
        });
    }
    return Promise.resolve({
        data: [],
        success: false,
    });
}

export async function updateSaveOneData(apiName: string, params: {
    dbname: string;
    guid: string;
    code: string;
    name: string;
    job: string;
}) {
    if (!params.dbname) return [];
    const res = await getApiData(apiName, params);
    if (res.ok) {
        return Promise.resolve({
            data: res.data,
            success: true,
        });
    }
    return Promise.resolve({
        data: [],
        success: false,
    });
}

// 导出模板
export async function templateCopyXlsxFile(params: {
    targetFile: string;
}) {
    try {
        const res = await getNestApiData('/draft/copyXlsxFile', 'post', params)
        return Promise.resolve({
            data: res.ok,
            msg: res.msg,
            success: res.ok,
        });
    } catch (error) {
        return Promise.resolve({
            data: '接口/template/importTemplate,请求失败！',
            success: false,
        });
    }
}


// 导入模板
export async function templateReadXlsxFile(params: {
    targetFile: string;
}) {
    try {
        const res = await getNestApiData('/draft/readXlsxFile', 'post', params);
        if (res.ok) {
            return Promise.resolve({
                data: res.data,
                success: res.ok,
            });
        }
        return Promise.resolve({
            data: [],
            success: false,
        });
    } catch (error) {
        return Promise.resolve({
            data: '接口/template/importTemplate,请求失败！',
            success: false,
        });
    }
}